package cn.stronglink.assetmanage.business.search.view;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.search.adapter.SearchAdapter;
import cn.stronglink.assetmanage.business.search.adapter.SearchSpinnerAdapter;
import cn.stronglink.assetmanage.business.search.view.AssisChange.AssisChangeFragment;
import cn.stronglink.assetmanage.entity.SearchAsset;
import cn.stronglink.assetmanage.utils.Constants;
import cn.stronglink.assetmanage.utils.ToastUtil;

/**
 * 查找检索
 * Created by zhengjinglan on 2018/6/19.
 */

public class SearchView {
    private Fragment fragment;

    @BindView(R.id.et_search_in_dev_name)
    EditText et_search_in_dev_name;
    @BindView(R.id.et_search_in_rfid)
    EditText et_search_in_rfid;
//    @BindView(R.id.imageBtn_search_rfid_scan)
//    ImageView imageBtn_search_rfid_scan;
    @BindView(R.id.et_search_in_assis_no)
    EditText et_search_in_assis_no;
//    @BindView(R.id.imageBtn_search_sn_scan)
//    ImageView imageBtn_search_sn_scan;
    @BindView(R.id.sp_type)
    Spinner sp_search;
//    @BindView(R.id.image_search)
//    ImageButton image_search;

    //资源列表
    @BindView(R.id.search_recyclerView)
    RecyclerView search_recyclerView;
    //资源列表adapter
    private SearchAdapter searchAdapter;

    public SearchView(Fragment fragment, View view, SearchAdapter searchAdapter){
        this.fragment = fragment;
        ButterKnife.bind(this, view);
        this.searchAdapter = searchAdapter;
        initData(view);
    }

    private void initData(View view){
        final List<String> datas = new ArrayList<>();
        datas.add(MyApplication.APP_CONTEXT.getResources().getString(R.string.search_spinner_all));
        datas.add(MyApplication.APP_CONTEXT.getResources().getString(R.string.search_spinner_rfid));
        datas.add(MyApplication.APP_CONTEXT.getResources().getString(R.string.search_spinner_sn));
        datas.add(MyApplication.APP_CONTEXT.getResources().getString(R.string.search_spinner_brandName));
        SearchSpinnerAdapter spinnerAdapter = new SearchSpinnerAdapter(view);
        sp_search.setAdapter(spinnerAdapter);


    }

    /**
     * 设置表单列表数据
     * @param listData 表单列表
     */
    public void setListData(List<SearchAsset> listData){
        if (searchAdapter !=null){
            searchAdapter.notifyDatasChanged(listData);
        }
    }

    /**
     * 跳转到变更资产页面
     * @param searchAsset
     */
   public void showChangeAssis(SearchAsset searchAsset){
       FragmentManager fragmentManager = fragment.getActivity().getSupportFragmentManager();
       FragmentTransaction transaction = fragmentManager.beginTransaction();
       Fragment changeFragment= new AssisChangeFragment();
       transaction.replace(R.id.frame_business, changeFragment);
       transaction.commit();
       Bundle bundle = new Bundle();
       bundle.putString(Constants.SEARCH_ASSIS_NO, searchAsset.getId_());
       changeFragment.setArguments(bundle);
   }

    public void showProgressDialog(String msg){
       Log.e("TAG",msg);

    }

    public void hideProgressDialog(){
        Log.e("TAG","取消");

    }
    public void showToast(String msg){
        ToastUtil.toastShort(msg);
    }

}
